package cn.edu.scau.cmi.xiongyi.Adapter;


import java.util.ArrayList;
import java.util.List;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;

public class AdapterOfClassController {
  //  @FXML
//    private TextField idText;
    
    @FXML
    private TableView<Student> tableView;

    @FXML
    private TextField numberText;

    @FXML
    private TextField nameText;

    @FXML
    private Button inputButton;
    @FXML
    private Button inputButton2;
    @FXML
    private TableColumn<Student, Integer> numberColumn;

    @FXML
    private TableColumn<Student, String> nameColumn;
    @FXML
    private final ObservableList<Student> studentdata = FXCollections.observableArrayList();
    static	List<Student> studentlist = new ArrayList<Student>();
    @FXML
    public void button() {
    	
    	int number = Integer.parseInt(numberText.getText());
    	String name = nameText.getText();
    	 Student student = new Student(name, number);
    	studentlist.add(student); 	
    	Target	target = new AdapterOfClass();
    	target.sortstudent(studentlist);
        numberColumn.setCellValueFactory(new PropertyValueFactory<Student, Integer>("number"));
        nameColumn.setCellValueFactory(new PropertyValueFactory<Student, String >("name"));
    	studentdata.clear();
    	for(Student students:studentlist) {
    		 studentdata.add(students);
    	}

    	tableView.setItems(studentdata);
    
    }
    @FXML
    public void button2() {
    	
    	int number = Integer.parseInt(numberText.getText());
    	String name = nameText.getText();
    	 Student student = new Student(name, number);
    	studentlist.add(student); 	
    	Target	target = new AdapterOfObject();
    	target.sortstudent(studentlist);
        numberColumn.setCellValueFactory(new PropertyValueFactory<Student, Integer>("number"));
        nameColumn.setCellValueFactory(new PropertyValueFactory<Student, String >("name"));
    	studentdata.clear();
    	for(Student students:studentlist) {
    		 studentdata.add(students);
    	}

    	tableView.setItems(studentdata);
    
    }
}
//112
//8774